package com.himore.api.web.controller.modules;

import java.util.List;

import com.himore.api.common.annotation.Log;
import com.himore.api.common.core.controller.BaseController;
import com.himore.api.common.core.domain.AjaxResult;
import com.himore.api.common.core.domain.entity.SysUser;
import com.himore.api.common.core.page.TableDataInfo;
import com.himore.api.common.enums.BusinessType;
import com.himore.api.common.utils.ErrorCodeUtil;
import com.himore.api.common.utils.SecurityUtils;
import com.himore.api.common.utils.StringUtils;
import com.himore.api.common.utils.poi.ExcelUtil;
import com.himore.api.web.model.TSysLike;
import com.himore.api.web.service.ITSysLikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import static com.himore.api.common.core.domain.AjaxResult.error;


/**
 * 点赞信息Controller
 * 
 * @author ruoyi
 * @date 2021-05-13
 */
@Api(tags = "点赞管理")
@Controller
@RequestMapping("/system/like")
public class TSysLikeController extends BaseController
{
    private String prefix = "system/like";

    @Autowired
    private ITSysLikeService tSysLikeService;

    @GetMapping()
    public String like()
    {
        return prefix + "/like";
    }

  /*  *//**
     * 查询点赞信息列表
     *//*
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSysLike tSysLike)
    {
        startPage();
        List<TSysLike> list = tSysLikeService.selectTSysLikeList(tSysLike);
        return getDataTable(list);
    }*/



    /**
     * 新增保存点赞信息
     */
    @ApiOperation(value = "点赞信息", notes = "likeType：1 帖子点赞， 2 评论点赞 ", produces = "application/json")
    @Log(title = "点赞信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody TSysLike tSysLike)
    {
        if(StringUtils.isBlank(tSysLike.getLikeType())){
            return error(ErrorCodeUtil.E_101,"您输入的点赞类型为空，请重新输入！");
        }
        if(("1".equals(tSysLike.getLikeType())) &&StringUtils.isBlank(tSysLike.getInvitationId())){
            return error(ErrorCodeUtil.E_101,"您输入的帖子ID为空，请重新输入！");
        }
        if(( "2".equals(tSysLike.getLikeType())) &&StringUtils.isNull(tSysLike.getCommentId())){
            return error(ErrorCodeUtil.E_101,"您输入的评论ID为空，请重新输入！");
        }

        return toAjax(tSysLikeService.insertTSysLike(tSysLike));
    }

    /**
     * 删除点赞信息
     */
    @ApiOperation(value = "取消点赞", notes = "取消点赞", produces = "application/json")
    @Log(title = "取消点赞", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(@RequestBody TSysLike tSysLike)
    {
        SysUser user =  SecurityUtils.getLoginUser().getUser();
        tSysLike.setUserId(user.getUserId());
        return toAjax(tSysLikeService.deleteTSysLikeByUserId(tSysLike));
    }
}
